<?php
require_once 'simpletest/unit_tester.php';
require_once 'simpletest/reporter.php';
require_once __DIR__ . '/../xml/CalendarXmlController.php';

class CalendarTest extends UnitTestCase
{
	/** 追加テスト */
	public function Test1100()
	{
		$obj = new Models_Calendar_Xml_Controller('201209');
		$Yoteibi = FALSE;
		$StartTime = '10:00';
		$EndTime = '11:00';
		$aryDraftAgeList
		= array(
				Models_Calendar_Controller::VALUE_GAKUNEN1,
				Models_Calendar_Controller::VALUE_GAKUNEN5
				);
		$EventCategory
		= Models_Calendar_Controller::VALUE_EVENT_CATEGORY_PERIOD_TRAINING;
		$Notice ='昼食持参';
		$MapId = FALSE;
		$obj->update('1347054746.8928', $Yoteibi, $StartTime, $EndTime, $aryDraftAgeList, $EventCategory, $Notice, $MapId);
//		$obj->saveToFile();
	}

	/** 検索テスト */
	public function Test2100()
	{
		$obj = new Models_Calendar_Xml_Controller('201209');
		$RET = $obj->getDateOfYotei('1347054746.8928');
		$this->assertEqual($RET[Lib_Request_DateTime::KEY_YEAR], '2012');
		$this->assertEqual($RET[Lib_Request_DateTime::KEY_MONTH], '09');
		$this->assertEqual($RET[Lib_Request_DateTime::KEY_DAY], '01');
	}

	/** リクエストパラメータからデータファイル名を決定するテスト */
	public function Test2200()
	{
		$_REQUEST[Lib_Request_DateTime::KEY_YEAR] = '1012';
		$_REQUEST[Lib_Request_DateTime::KEY_MONTH] = '09';
		$obj = new Models_Calendar_Xml_Controller();
		$RET = $obj->getDateOfYotei('1347054746.8928');
		$this->assertEqual($RET[Lib_Request_DateTime::KEY_YEAR], '2012');
		$this->assertEqual($RET[Lib_Request_DateTime::KEY_MONTH], '09');
		$this->assertEqual($RET[Lib_Request_DateTime::KEY_DAY], '01');
	}

	/** 更新テスト */
	public function Test2300()
	{
		$_REQUEST[Lib_Request_DateTime::KEY_YEAR] = '1012';
		$_REQUEST[Lib_Request_DateTime::KEY_MONTH] = '09';
		$obj = new Models_Calendar_Xml_Controller();
		$RET = $obj->getDateOfYotei('1347054746.8928');
		print_r($RET);
	}

	/** HTTPリクエストから更新 */
	public function Test2400()
	{
		$_REQUEST["AssemblyPlace"]="1278052130";
		$_REQUEST["START_TIME_HOUR"]="10";
		$_REQUEST["START_TIME_MINUTE"]="0";
		$_REQUEST["END_TIME_HOUR"]="11";
		$_REQUEST["END_TIME_MINUTE"]="0";
		$_REQUEST["DraftAge"][0]="２年生";
		$_REQUEST["DraftAge"][1]="５年生";
		$_REQUEST["EVENT_CATEGORY"]="定期練習";
		$_REQUEST["NOTICE"]="昼食持参";
		$_REQUEST["regist"]="変更";
		$_REQUEST["YOTEIID"]="1347054747";
		$_REQUEST["year"]="2012";
		$_REQUEST["month"]="9";
	}

	/** HTTPリクエスト相関チェックテスト */
	public function Test3100()
	{
		$obj = new Models_Calendar_Xml_Controller('201209');
		$sYear = $obj->getYearFromFileName();
		$this->assertEqual($sYear, '2012');
		$sMonth = $obj->getMonthFromFileName();
		$this->assertEqual($sMonth, '9');
	}

	/** 予定日取得テスト */
	public function Test4100()
	{
		$obj = new Models_Calendar_Xml_Controller('201209');
		$_REQUEST['YOTEIID'] = '1347054746.8928';
		$Ret = $obj->getYoteibi();
		$this->assertEqual($Ret, '2012年9月1日（土曜日）');
	}

	/** 中止設定テスト */
	public function Test5100()
	{
		$sId = '1347054746.8928';
		$obj = new Models_Calendar_Xml_Controller('201209');
		$Ret = $obj->setStopFlg($sId);
		$dataset = $obj->searchId($sId);
		$this->assertEqual($dataset[Models_Calendar_Controller::KEY_STOP_FLG], '1');
		$Ret = $obj->setStopFlg($sId, TRUE);
		$dataset = $obj->searchId($sId);
		$this->assertEqual($dataset[Models_Calendar_Controller::KEY_STOP_FLG], '0');
	}
}